package com.jhm.bing_fa_rong_qi;

import java.util.concurrent.ConcurrentSkipListSet;

public class ConcurrentSkipListSetExample {
    public static void main(String[] args) {
        // 线程安全的ConcurrentSkipListSet
        ConcurrentSkipListSet<Integer> concurrentSet = new ConcurrentSkipListSet<>();

        // 添加元素
        concurrentSet.add(3);
        concurrentSet.add(1);
        concurrentSet.add(4);
        concurrentSet.add(2);

        // 遍历集合
        for (Integer number : concurrentSet) {
            System.out.println(number);
        }

        // 检查元素是否存在
        boolean contains = concurrentSet.contains(3);
        System.out.println("Contains 3: " + contains);

        // 删除元素
        boolean removed = concurrentSet.remove(2);
        System.out.println("Removed 2: " + removed);

        // 再次遍历集合
        System.out.println("After removing 2:");
        for (Integer number : concurrentSet) {
            System.out.println(number);
        }
    }
}
